# -*- coding: utf-8 -*-
#
# Author: QianfuFinance
#
'''
    ``crawler_baidu_stock_table`` 的持久化对象
'''
from baidustock.database import Base, DBBase, DBSession
from sqlalchemy import Column, String, DateTime, Integer
import logging


logger = logging.getLogger(__name__)


class CrawlerBaiduStockTable(Base, DBBase):
    '''
        表 ``crawler_baidu_stock_table`` 的持久化对象
    '''
    __tablename__ = 'crawlerbaidustock'

    instance_id = Column('instance_id', Integer, primary_key=True)
    start_time = Column('start_time', DateTime)
    finish_time = Column('finish_time', DateTime)
    finish_reason = Column('finish_reason', String(255))
    database_error_count = Column('database_error_count', Integer)
    item_scraped_count = Column('item_scraped_count', Integer)

    @classmethod
    def insert(cls, obj):
        '''
            插入对象
        '''
        with DBSession() as session:
            session.add(obj)
            session.flush()
